import JSONbig from 'json-bigint';
import { hostApi, hostApiConfig } from '@/api';

const Index = (projectId: any) => ({
  autoQuery: true,
  transport: {
    read: ({ data }: any) => {
      const type = data?.type;
      return type && projectId ? ({
        ...hostApiConfig.loadHostsAppList(type || ''),
        transformResponse: (res:any) => {
          const newRes = JSONbig.parse(res);
          newRes?.content?.forEach((item: { devopsHostDTO: any; hostId: any; }) => {
            if (item.devopsHostDTO) {
              // eslint-disable-next-line no-param-reassign
              item.hostId = item.devopsHostDTO;
            }
          });
          return newRes;
        },
      }) : undefined;
    },
  },
});

export default Index;
